package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpiInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// upi--获取一条记录
func NewUpiInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpiInfoLogic {
	return &UpiInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpiInfoLogic) UpiInfo(req *types.UpiInfoRequest) (resp *types.UpiInfoResponse, err error) {
	rpcReq := rpc.UpiInfoRequest{
		Id: req.Id,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.TenantChannel.UpiInfo(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}

	return &types.UpiInfoResponse{
		Upi: types.Upi{
			Id:           rpcResp.Id,
			CreatedAt:    rpcResp.CreatedAt,
			UpdatedAt:    rpcResp.UpdatedAt,
			Upi:          rpcResp.Upi,
			MinAmount:    rpcResp.MinAmount,
			MaxAmount:    rpcResp.MaxAmount,
			DailyTimes:   rpcResp.DailyTimes,
			DailyAmount:  rpcResp.DailyAmount,
			RemainTimes:  rpcResp.RemainTimes,
			RemainAmount: rpcResp.RemainAmount,
			VisionLevel:  rpcResp.VisionLevel,
			IsDisplay:    rpcResp.IsDisplay,
		},
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
